// Padillatech.com 2007

//request constructor
function Request(){
	var _self = this;
	_self.request = null;
	_self.querystring = null;
	_self.callback = function(){return};
	_self.responseType = 'text';
	_self.contentType = 'text/html';
	_self.loadfunc = function(){};
	
	try {
		_self.request = new XMLHttpRequest();
		_self.request.overrideMimeType(_self.contentType);
	} catch(trymicrosoft){
		try {
			_self.request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				_self.request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				alert("You will not be able to view this site correctly because you either have javascript turned off or have an older unsupported browser.");
				return null;
			}
		}
	}
	
	//makes the actual call to the server
	//takes the type of call, either post or get, the url of the page on the server and if the call is async or not
	_self.doRequest = function(type, URL, isSync){
		
		_self.request.open(type, URL, isSync);
	
		_self.request.onreadystatechange = function(){
					_self.loadfunc();
						
												if(_self.request.readyState == 4){
													if(_self.request.status == 200){
														if(_self.responseType == 'text'){
															var response = _self.request.responseText; //alert(response);
														}else
															if(_self.responseType == 'xml')
																var response = _self.request.responseXML;
																
														_self.callback(response);		
														//alert(response);
													}
												}
											};
		
		_self.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		_self.request.send(_self.querystring);
	}
	
	//sets response to be xml or text
	_self.setResponseType = function(type){
		_self.responseType = type;
	}
	
	//sets the callback function
	_self.setCallback = function(callback){
		_self.callback = callback;
	}
		
	//sets the string to use if the request type is a post	
	_self.setQuerystring = function(querystring){
		_self.querystring = querystring;	
	}
	
	//sets the load function used for a wait timer, etc	
	_self.setLoad = function(loadfunc){
		_self.loadfunc = loadfunc;	
	}

}
